<template>
  <el-dialog
    :title="option.title"
    :visible.sync="option.isShow"
    width="70%"
    :close-on-click-modal="false"
    @open="openDialog"
    @close="closeDialog('ruleForm')"
  >
    <el-row :gutter="10">
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-col :span="12">
          <el-form-item label="相关渠道号" prop="RELECHANNEL">
            <el-input size="small" placeholder="请输入相关渠道号" v-model="ruleForm.RELECHANNEL"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="分段间隔" prop="TIMEINTERVAL">
            <el-input size="small" placeholder="请输入分段间隔" v-model="ruleForm.TIMEINTERVAL"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最长等待时长" prop="MAXWAITTIME">
            <el-input size="small" placeholder="请输入最长等待时长" v-model="ruleForm.MAXWAITTIME"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="工时占有率" prop="SHAREOFWORK">
            <el-input size="small" placeholder="请输入工时占有率" v-model="ruleForm.SHAREOFWORK"></el-input>
          </el-form-item>
        </el-col>

        <el-col :span="24">
          <el-form-item>
            <el-button type="primary" size="mini" @click="submitForm('ruleForm')">保存</el-button>
            <el-button @click="resetForm('ruleForm')" size="mini">重置</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-row>
  </el-dialog>
</template>

<script>
import getGlobalParams from "@/common/utils/getGlobalParams";
import request from "@/common/utils/requestWFM";
import upadte from "@/message/wfm/FTEForecast/forecastParam/forecastUpdate";

export default {
  props: {
    option: Object
  },
  computed: {
    isShow: {
      get: function() {
        return this.option.isShow;
      },
      set: function(newValue) {
        this.option.isShow = newValue;
      }
    }
  },
  mounted() {},
  data() {
    return {
      ruleForm: {
        RELECHANNEL: "",
        TIMEINTERVAL: "",
        MAXWAITTIME: "",
        SHAREOFWORK: ""
      },
      rules: {
        // CHANNELTYPE: [{
        //   required: true,
        //   message: '请选择渠道',
        //   trigger: 'change'
        // }],
        // SCORETEMPLATEID: [{
        //   required: true,
        //   message: '请输入模板编号',
        //   trigger: 'change'
        // }]
      },
      loading: false
    };
  },
  created() {},
  methods: {
    openDialog() {
      if (this.$refs["ruleForm"] != undefined) {
        this.$refs["ruleForm"].clearValidate();
      }
      this.ruleForm = this.option.row;
      console.log(this.ruleForm)
    },
    closeDialog(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].clearValidate();
      }
      // this.$refs[formName].clearValidate();
      this.$refs[formName].resetFields();
    },
    //保存
    submitForm(formName) {
      this.$refs[formName].validate(async valid => {
        if (valid) {
          let resBody;
          resBody = new upadte();
          resBody.data.RELECHANNEL = this.ruleForm.RELECHANNEL;
          resBody.data.TIMEINTERVAL = this.ruleForm.TIMEINTERVAL;
          resBody.data.MAXWAITTIME = this.ruleForm.MAXWAITTIME;
          resBody.data.SHAREOFWORK = this.ruleForm.SHAREOFWORK;
          let response = await request(resBody);
          if (response.SYS_HEAD.ReturnCode == "000000") {
              this.$message({
                type: "success",
                message: "修改成功！"
              });
            this.isShow = false;
            this.$emit("refreshTable");
          } else {
            this.$message({
              type: "error",
              message:
                "请求失败，错误码:" +
                response.SYS_HEAD.ReturnCode +
                "，错误信息：" +
                response.SYS_HEAD.ReturnMessage
            });
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      if (this.$refs[formName] != undefined) {
        this.$refs[formName].clearValidate();
        this.$refs[formName].resetFields();
      }
    }
  }
};
</script>

<style scoped>
</style>
